#ifndef PNGSTREAM_H
#define PNGSTREAM_H

#define PNGSIGSIZE 4
#define PNG_READ_DITHER_SUPPORTED

#include <png.h>

#include <iostream>
#include <istream>

class pngstream {

  png_structp png_ptr;
  png_infop info_ptr;

  unsigned int row_index;

public:

  struct png_info {
    png_uint_32 width;
    png_uint_32 height;
    int bitdepth;
    int color_type;
    png_uint_32 channels;
    int interlace_type;
  } pngheader;

  bool initializeInput(FILE *input, bool input_to_grayscale);
  unsigned char *readLine();
  bool hasNext();
  void finishInput();

  bool initializeOutput(FILE *output, int width, int height, int bit_depth, int color_type);
  bool write(unsigned char **data);
  void finishOutput();

  pngstream() : row_index(0) {};

protected:

  bool validate(FILE *input);

};

#endif